package com.wjj.happytime.application;

import android.app.Application;

import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import com.jiongbull.jlog.JLog;
import com.wjj.happytime.db.MyDbHelper;
import com.wjj.happytime.my_interface.HttpService;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * created by Wang_JunJie at 2017/1/9
 */
public class BaseApplication extends Application {

  private HttpService httpService;
  public MyDbHelper dbHelper;
  public SQLiteDatabase db;

  @Override
  public void onCreate() {
    super.onCreate();
    httpService = new Retrofit.Builder()
        .baseUrl("https://www.baidu.com/")//这里的网址只是用来占位，没有实际意义
        .addConverterFactory(GsonConverterFactory.create())
        .build()
        .create(HttpService.class);
    //初始化JLog
    JLog.init(this).setDebug(true);

    //创建数据库
    dbHelper = new MyDbHelper(this, "myDB.db", null, 1);
    db = dbHelper.getWritableDatabase();
    //1、打开Preferences，名称为setting，如果存在则打开它，否则创建新的Preferences
    SharedPreferences settings = getSharedPreferences("sp", 0);
//2、让setting处于编辑状态
    SharedPreferences.Editor editor = settings.edit();
//3、存放数据
    editor.putString("name", "wjj");
//4、完成提交
    editor.commit();

  }

  public HttpService getService() {

    return httpService;
  }
}
